package com.wang.abstractrouting.datasource.controller;

import com.wang.abstractrouting.datasource.DynamicDataSource;
import com.wang.abstractrouting.datasource.mapper.UserMapper;
import com.wang.abstractrouting.datasource.model.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: wangning1@abupdate.com
 * @date: 2023-12-18 18:38
 **/
@RestController
public class UserController {

    @Resource
    private UserMapper userMapper;

    /**
     * 数据源1
     *
     * @return
     */
    @GetMapping("/listBySource1")
    public List<User> listBySource1(){
        DynamicDataSource.flag.set("source1");
        return userMapper.selectList(null);
    }

    /**
     * 数据源2
     *
     * @return
     */
    @GetMapping("/listBySource2")
    public List<User> listBySource2(){
        DynamicDataSource.flag.set("source2");
        return userMapper.selectList(null);
    }
}